<?php

require_once( dirname(__FILE__).'/../libs/passwordhash.php' );

function removeDiacritics( $input )
{
    $a = array(
        "ö" => "o",
        "ű" => "u",
        "ő" => "o",
        "ü" => "u",
        "ł" => "l",
        "ż" => "z",
        "ń" => "n",
        "ć" => "c",
        "ę" => "e",
        "ś" => "s",
        "ŕ" => "r",
        "á" => "a",
        "ä" => "a",
        "ĺ" => "l",
        "č" => "c",
        "é" => "e",
        "ě" => "e",
        "í" => "i",
        "ď" => "d",
        "ň" => "n",
        "ó" => "o",
        "ô" => "o",
        "ř" => "r",
        "ů" => "u",
        "ú" => "u",
        "š" => "s",
        "ť" => "t",
        "ž" => "z",
        "ľ" => "l",
        "ý" => "y",
        "Ŕ" => "R",
        "Á" => "A",
        "Ä" => "A",
        "Ĺ" => "L",
        "Č" => "C",
        "É" => "E",
        "Ě" => "E",
        "Í" => "I",
        "Ď" => "D",
        "Ň" => "N",
        "Ó" => "O",
        "Ô" => "O",
        "Ř" => "R",
        "Ů" => "U",
        "Ú" => "U",
        "Š" => "S",
        "Ť" => "T",
        "Ž" => "Z",
        "Ľ" => "L",
        "Ý" => "Y",
        "Ä" => "A");

     return strtr( $input, $a );   
}
     
class Customer
{
    public $id;
    public $sex;
    public $name;
    public $namenodiacritics;
    public $surname;
    public $surnamenodiacritics;
    public $passwordhash;
    public $passwordsalt;
    public $emailaddress;
    public $mobilphone;
    public $state;
    public $credits;
    
    public function __construct()
    {
        $this->id = 0;
        $this->sex = null;
        $this->name = "";
        $this->namenodiacritics = "";
        $this->surname = "";
        $this->surnamenodiacritics = "";
        $this->passwordhash = "";
        $this->passwordsalt = "";
        $this->emailaddress = "";
        $this->mobilphone = null;
        $this->state = -1;
        $this->credits = null;
    }
    
    private static function valueFromPost( $name, & $value )
    {
         if (isset( $_POST[ $name ]))
         {
             $value = $_POST[ $name ];
             return true;
         }
         
         return false;
    }
    
    public function fromPost()
    {
        Customer::valueFromPost( "sex", $this->sex );
    
        if (! Customer::valueFromPost( "name", $this->name ))
            return false;
    
        if (! Customer::valueFromPost( "surname", $this->surname ))
            return false;
    
        $password = "";
        if (! Customer::valueFromPost( "password", $password ))
            return false;
        
        PasswordHash::hashPassword( $password, $this->passwordsalt, $this->passwordhash );

        if (! Customer::valueFromPost( "email", $this->emailaddress ))
            return false;
    
        Customer::valueFromPost( "mobil", $this->mobilphone );

        $this->namenodiacritics = removeDiacritics( $this->name );
        $this->surnamenodiacritics = removeDiacritics( $this->surname );

        return true;
    }
};

// prihlaseny user ulozeny v session - ma email a meno, ktore vypisem vo footeri
class LoggedUser
{
    public $id;
    public $emailAddress;
    public $name;
    public $surname;
};

class PriceList
{
    public $dayType;
    public $fromHour;
    public $toHour;
    public $price;
    public $dayDate;
};

class MyDateTime
{
    
    public $year;
    public $month;
    public $day;
    public $hour;
    public $minute;
    public $second;
      
    private $m_timestamp;
    
    public function MyDateTime()
    {
        $this->m_timestamp = -1;
        $this->year = 0;
        $this->month = 0;
        $this->day = 0;
        $this->hour = 0;
        $this->minute = 0;
        $this->second = 0;
    }
    
    public static function fromPqDateTime( $pqDateTime )
    {
        //2012-01-04 00:00:00+01
    }
    
    public static function fromPqDate( $pqDate )
    {
        $retValue = new MyDateTime();
        if (! isset($pqDate) || $pqDate == "")
            return $retValue;
        
        $dateTime = new DateTime( $pqDate ); 
        $retValue->m_timestamp = $dateTime->getTimestamp();
        
        $dt = getDate( $retValue->m_timestamp );
        $retValue->year = $dt[ 'year' ];
        $retValue->month = $dt[ 'mon' ];
        $retValue->day = $dt[ 'mday' ];
        
        return $retValue;
    }
    
    public function toPqDateTime()
    {
        return date( "Y-m-d H:i:s", $this->m_timestamp );
    }
    
    public function toPqDate()
    {
        return date( "Y-m-d", $this->m_timestamp );
    }
    
    public function toDateTime()
    {
        return date( "d.m.Y H:i:s", $this->m_timestamp );
    }
    
    public function toDate()
    {
        return date( "d.m.Y", $this->m_timestamp );
    }
    public function timeStamp()
    {
        return $this->m_timestamp;
    }
};

?>
